
#include "nane/RenderSystem/RenderSystemImpl_.h"
#include "nane/RenderSystem/VertexBufferImpl_.h"
#include "nane/RenderSystem/IndexBufferImpl_.h"
#include "nane/RenderSystem/TextureImpl_.h"
#include "nane/RenderSystem/ConstantBufferImpl_.h"
#include "nane/RenderSystem/VertexShaderImpl_.h"
#include "nane/RenderSystem/PixelShaderImpl_.h"

#include "nane/core/assert.h"

namespace nane
{
    ////////////////////////////////////////////////////////////////////////////////////////////////
    RenderSystem::Implementation::Implementation()
        : SubSystem<IRenderSystem>::Implementation("IRenderSystem")
    {
        
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////
    RenderSystem::Implementation::~Implementation()
    {
        
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////
    void RenderSystem::Implementation::Release( VertexBuffer::Implementation* _vertexBufferImpl )
    {
        NANE_ASSERT_R( interface != NULL, "RenderSystem must be initialized" );
        NANE_ASSERT_R( this == _vertexBufferImpl->creator, "VertexBuffer must be valid" );
        IVertexBuffer* vertextBufferInterface = _vertexBufferImpl->interface;
        delete _vertexBufferImpl;
        interface->ReleaseVertexBuffer(vertextBufferInterface);
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////
    void RenderSystem::Implementation::Release( IndexBuffer::Implementation* _indexBufferImpl )
    {
        NANE_ASSERT_R( interface != NULL, "RenderSystem must be initialized" );
        NANE_ASSERT_R( this == _indexBufferImpl->creator, "IndexBuffer must be valid" );
        IIndexBuffer* indexBufferInterface = _indexBufferImpl->interface;
        delete _indexBufferImpl;
        interface->ReleaseIndexBuffer(indexBufferInterface);
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////
    void RenderSystem::Implementation::Release( Texture::Implementation* _textureImpl )
    {
        NANE_ASSERT_R( interface != NULL, "RenderSystem must be initialized" );
        NANE_ASSERT_R( this == _textureImpl->creator, "Texture must be valid" );
        ITexture* textureInterface = _textureImpl->interface;
        delete _textureImpl;
        interface->ReleaseTexture(textureInterface);
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////
    void RenderSystem::Implementation::Release( ConstantBuffer::Implementation* _constantBufferImpl )
    {
        NANE_ASSERT_R( interface != NULL, "RenderSystem must be initialized" );
        NANE_ASSERT_R( this == _constantBufferImpl->creator, "ConstantBuffer must be valid" );
        IConstantBuffer* constantBufferInterface = _constantBufferImpl->interface;
        delete _constantBufferImpl;
        interface->ReleaseConstantBuffer(constantBufferInterface);
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////
    void RenderSystem::Implementation::Release( VertexShader::Implementation* _vertexShaderImpl )
    {
        NANE_ASSERT_R( interface != NULL, "RenderSystem must be initialized" );
        NANE_ASSERT_R( this == _vertexShaderImpl->creator, "VertexShader must be valid" );
        IVertexShader* vertexShaderInterface = _vertexShaderImpl->interface;
        delete _vertexShaderImpl;
        interface->ReleaseVertexShader(vertexShaderInterface);
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////
    void RenderSystem::Implementation::Release( PixelShader::Implementation* _pixelShaderImpl )
    {
        NANE_ASSERT_R( interface != NULL, "RenderSystem must be initialized" );
        NANE_ASSERT_R( this == _pixelShaderImpl->creator, "PixelShader must be valid" );
        IPixelShader* pixelShaderInterface = _pixelShaderImpl->interface;
        delete _pixelShaderImpl;
        interface->ReleasePixelShader(pixelShaderInterface);
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////
}   // namespace nane
